cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/TableA16.log", replace

clear all
set more off

matrix Results = J(33, 9, -9)

use "RawData/GallupDataBJPS.dta", clear

// Drops Unrepresentative Series
drop if drops == "All" | regexm(drops, "Party")
// Drops Obs. w/o Gender
drop if female < 0
// Drops Obs. w/o Weights
drop if final_weight < 0
// Drops Obs. w/o Dem., Ind., or Rep.
keep if party == -1 | party == 0 | party == 1
// Keeps In-Person Surveys
keep if survey == 1

// Sets the Survey Date as the Mid-Point in Field
gen middle_date = .
replace middle_date = floor((start_date + end_date) / 2)
sort middle_date
format middle_date %td
gen year = year(middle_date)  

// Codes Dem. as 0, Ind. as 1/2, and Rep. as 1
// Partisan 1 = Leaners Ind, Partisan 2 = Leaners as Partisans
gen partisan = 0 if party == -1
replace partisan = 1 if party == 1
replace partisan = .5 if party == 0

save "ProcessedData/temp.dta", replace

// Job Type
use "ProcessedData/temp.dta", clear
drop if industry < 0 | industry == 12
gen inc = log(1000 + lower_bound_income) if lower_bound_income ~= -9 & lower_bound_income ~= -99
areg inc i.industry, absorb(series) 
drop inc

gen high = (industry == 2 | industry == 8)
gen mid = (industry == 3 | industry == 4 | industry == 5 | industry == 6) 
gen low = (industry == 1 | industry == 7 | industry == 9 | industry == 10)
gen none = (industry ==  11)
foreach var of varlist high-none {
gen femaleX`var' = female * `var'
}
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan mid-femaleXnone [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 1] = _b[femaleXhigh]
mat Results[`j' + 1, 1] = -_se[femaleXhigh]
cap count if high == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 1] = r(N)
mat Results[`j', 2] = _b[femaleXmid]
mat Results[`j' + 1, 2] = -_se[femaleXmid]
cap count if mid == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 2] = r(N)
mat Results[`j', 3] = _b[femaleXlow]
mat Results[`j' + 1, 3] = -_se[femaleXlow]
cap count if low == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 3] = r(N)
mat Results[`j', 4] = _b[femaleXnone]
mat Results[`j' + 1, 4] = -_se[femaleXnone]
cap count if none == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 4] = r(N)
}
}

// Income
use "ProcessedData/temp.dta", clear
drop if lower_bound_income < 0 | missing_income == 1
egen income_50 = median(lower_bound_income), by (series)
gen rich = (lower_bound_income >= income_50)
gen femaleXyes = female * (rich == 1)
gen femaleXno = female * (rich == 0)
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan rich femaleXyes femaleXno [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 5] = _b[femaleXyes]
mat Results[`j' + 1, 5] = -_se[femaleXyes]
cap count if rich == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 5] = r(N)
mat Results[`j', 6] = _b[femaleXno]
mat Results[`j' + 1, 6] = -_se[femaleXno]
cap count if rich == 0 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 6] = r(N)
}
}

// Employment
use "ProcessedData/temp.dta", clear
drop if employment < 0
gen full = (employment == 1)
gen part = (employment == 2)
gen none = (employment == 3)
foreach var of varlist full-none {
gen femaleX`var' = female * `var'
}
forvalues i = 1953(4)1993 {
local j = 1 + 3*(`i' - 1953)/4
cap areg partisan part-femaleXnone [aweight = final_weight] /*
*/ if year >= `i' & year <= `i' + 3, absorb(series) robust
local temp = _rc
if `temp' == 0 {
mat Results[`j', 7] = _b[femaleXfull]
mat Results[`j' + 1, 7] = -_se[femaleXfull]
cap count if full == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 7] = r(N)
mat Results[`j', 8] = _b[femaleXpart]
mat Results[`j' + 1, 8] = -_se[femaleXpart]
cap count if part == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 8] = r(N)
mat Results[`j', 9] = _b[femaleXnone]
mat Results[`j' + 1, 9] = -_se[femaleXnone]
cap count if none == 1 & year >= `i' & year <= `i' + 3
mat Results[`j' + 2, 9] = r(N)
}
}

matlist Results

log close
